package com.fact.actions;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.fact.dto.MakeDTO;
import com.fact.dto.MarketDTO;
import com.fact.dto.UserDTO;
import com.fact.models.MakeService;
import com.fact.models.MarketService;
import com.fact.models.ResponsibilityService;
import com.fact.utils.AppConstant;

public class Responsibility extends BaseAction implements SessionAware{
	
	private static final long serialVersionUID = 1L;
	private Map<String,Object> session;
	private ArrayList<UserDTO> userList;
	
	private ArrayList<MakeDTO> makeList;
	private ArrayList<MarketDTO> marketList;
	
	private String page=AppConstant.RESPONSIBILITY;
	private String pageTitle="FMtool - Responsibility List";
	private String opType;

	ResponsibilityService responsibilityService=new ResponsibilityService();
	MakeService makeService=new MakeService();
	MarketService marketService=new MarketService();
	UserDTO user=new UserDTO();

	  private List<String> selectedMakes;
	  private List<String> selectedMarkets;

	public String responsibilityList()
	{
		if(opType==null || (!opType.equalsIgnoreCase("save") && !opType.equalsIgnoreCase("delete") && !opType.equalsIgnoreCase("edit")))
			this.session.put("operation_message", null);
		
		userList= responsibilityService.getResponsiblityList();
		
		makeList= makeService.getMakeList();
		marketList=marketService.getMarketList();
		
		return SUCCESS;
	}
	public String editResponsibility()
	{
		System.out.println(user.getUserId());
		System.out.println(user.getUserTypeId());
		System.out.println(selectedMakes.size());
		System.out.println(selectedMarkets.size());
		responsibilityService.updateResponsibility(user, selectedMakes, selectedMarkets);
		
		this.session.put("operation_message","Responsibility has successfully been updated.");
		return SUCCESS;
		
		
	}
	
	
	public ArrayList<UserDTO> getUserList() {
		return userList;
	}


	public void setUserList(ArrayList<UserDTO> userList) {
		this.userList = userList;
	}


	public String getPage() {
		return page;
	}


	public void setPage(String page) {
		this.page = page;
	}


	public String getPageTitle() {
		return pageTitle;
	}


	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}


	public String getOpType() {
		return opType;
	}


	public void setOpType(String opType) {
		this.opType = opType;
	}


	public void setSession(Map<String, Object> session) 
	{
		this.session = session;
	}
	public ServletContext getServletContext()
	{
		return ServletActionContext.getServletContext();
	}


	public ArrayList<MakeDTO> getMakeList() {
		return makeList;
	}


	public void setMakeList(ArrayList<MakeDTO> makeList) {
		this.makeList = makeList;
	}


	public ArrayList<MarketDTO> getMarketList() {
		return marketList;
	}


	public void setMarketList(ArrayList<MarketDTO> marketList) {
		this.marketList = marketList;
	}
	public UserDTO getUser() {
		return user;
	}
	public void setUser(UserDTO user) {
		this.user = user;
	}
	
	public List<String> getSelectedMakes() {
		return selectedMakes;
	}
	public void setSelectedMakes(List<String> selectedMakes) {
		this.selectedMakes = selectedMakes;
	}
	public List<String> getSelectedMarkets() {
		return selectedMarkets;
	}
	public void setSelectedMarkets(List<String> selectedMarkets) {
		this.selectedMarkets = selectedMarkets;
	}

    
}
